<?php
class User_Model_Parameter extends Zend_Db_Table{
	protected $_name = 'parameter';
	protected $_primary = 'idParameter';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	/* select demo */
	public function selectSetting($code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/parameter/route/selectSetting/code/".$code);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;	
	}
	
	/* insert demo */
	/*public function insertSetting($data)
	{
		$adapter = $this->getDefaultAdapter();
		try {
			$adapter->beginTransaction();
			$adapter->insert('parameter', $data);
			$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}*/
	/* update demo */
	public function updateSetting($data)
	{ // co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/parameter/route/updateSetting/name/".urlencode($data['parameter_name'])."/value/".urlencode($data['parameter_value']));
		return $return->getBody();
	}
	/*public function deleteParameterByName($parameter_name)
	{
		$adapter = $this->getDefaultAdapter();
		try {
			$adapter->beginTransaction();
			$where = $adapter->quoteInto('parameter_name = ?', $parameter_name);
			$adapter->delete('parameter',$where);
			$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}*/
}